#include <algorithm>

#include "locatorcell.h"


locator_cell_t::locator_cell_t() : cell_t(), center_idx_(-1)
{
}

locator_cell_t::locator_cell_t(point_t const & center) : cell_t(center), center_idx_(-1)
{
}

int locator_cell_t::get_parent(segment_t const & seg) const
{
	if(empty())
		return -1;
	int distance = &seg - &segments_[0];
	if(distance >= 0 && distance < size())
		return idxs_[distance];
	return -1;
}

int locator_cell_t::get_parent() const
{
	return center_idx_;
}

void locator_cell_t::set_center_parent(int parent)
{
	center_idx_ = parent;
}

locator_cell_inserter::locator_cell_inserter(int idx) : inserter(), idx_(idx)
{
}

void locator_cell_inserter::operator() (locator_cell_t & cell, segment_t const & segment) const
{
	inserter::operator() (cell, segment);
	if(cell.size() > cell.idxs_.size())
		cell.idxs_.push_back(idx_);
}
